import sys
arr=['D:\\', 'C:\\Python27\\ArcGIS10.2\\Lib\\idlelib', 'C:\\Windows\\SYSTEM32\\python27.zip', 'C:\\Python27\\ArcGIS10.2\\DLLs', 'C:\\Python27\\ArcGIS10.2\\lib', 'C:\\Python27\\ArcGIS10.2\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.2', 'C:\\Python27\\ArcGIS10.2\\lib\\site-packages', 'C:\\Program Files\\ArcGIS\\Server\\bin', 'C:\\Program Files\\ArcGIS\\Server\\arcpy', 'C:\\Program Files\\ArcGIS\\Server\\ArcToolbox\\Scripts']
sys.path.extend(arr);


import arcpy
import arcgisscripting
def createMapServer(mxdPath,conServerDefPath,outPath,serverName,summary,tags):
	# define local variables
	wrkspc = outPath
	mapDoc = arcpy.mapping.MapDocument(mxdPath)
	con = conServerDefPath
	service = serverName
	sddraft = wrkspc + service + '.sddraft'
	sd = wrkspc + service + '.sd'
	summary = summary
	tags = tags

	# create service definition draft
	analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', 
	                                          con, True, None, summary, tags)

	# stage and upload the service if the sddraft analysis did not contain errors
	if analysis['errors'] == {}:
	    # Execute StageService
	    arcpy.StageService_server(sddraft, sd)
	    # Execute UploadServiceDefinition
	    arcpy.UploadServiceDefinition_server(sd, con)
	    return '';
	else: 
	    # if the sddraft analysis contained errors, display them
		return analysis['errors'];

